import { http } from "@/utils/request";

import type {
  LifeCycleEntity,
  PageResultType,
  createLifeCycleParams,
  queryPagesType,
  Datum,
  LifeGlobalStatus,
  saveLifecycleNodeParams,
  saveLifecycleEdgeParams,
  lifecycleNode,
  lifecycleEdge,
} from "@/interface/lifecycle.ts";
// 创建生命周期
export const createLifeCycle = (
  params: createLifeCycleParams,
): Promise<LifeCycleEntity> => {
  return http.post("/lifecycle/create", params);
};

export const updateLifeCycle = (
  params: createLifeCycleParams,
): Promise<null> => {
  return http.put("/lifecycle/edit", params);
};

export const deleteLifeCycle = (id: string): Promise<null> => {
  return http.delete(`/lifecycle/${id}`);
};

export const deleteLifeCycleBatch = (ids: string[]): Promise<null> => {
  return http.post(`/lifecycle/deleteBatch`, ids);
};

export const copyLifeCycle = (id: string): Promise<null> => {
  return http.post(`/lifecycle/copy/${id}`);
};

export const getLifeCycle = (id: string): Promise<LifeCycleEntity> => {
  return http.get(`/lifecycle/${id}`);
};

export const listLifeCycle = (
  params: queryPagesType,
): Promise<PageResultType<LifeCycleEntity>> => {
  return http.post(`/lifecycle/list`, params);
};

// 工作项列表
export const listLifeGlobalStatus = (
  params: queryPagesType,
): Promise<PageResultType<LifeGlobalStatus>> => {
  return http.post(`/lifeGlobalStatus/list`, params);
};

// 工作项创建
export const createLifeGlobalStatus = (
  params: LifeGlobalStatus,
): Promise<LifeGlobalStatus> => {
  return http.post(`/lifeGlobalStatus/create`, params);
};

// 工作项编辑
export const editLifeGlobalStatus = (
  params: LifeGlobalStatus,
): Promise<null> => {
  return http.put(`/lifeGlobalStatus/edit`, params);
};

// 工作项删除
export const deleteLifeGlobalStatus = (id: string): Promise<null> => {
  return http.delete(`/lifeGlobalStatus/${id}`);
};

// 工作项删除
export const deleteLifeGlobalStatusBatch = (ids: string[]): Promise<null> => {
  return http.post(`/lifeGlobalStatus/deleteBatch`, ids);
};

// 工作项查询
export const getLifeGlobalStatus = (id: string): Promise<LifeGlobalStatus> => {
  return http.post(`/lifeGlobalStatus/${id}`);
};

// 查询规则状态列表

export const getLifecycleFieldList = (): Promise<Datum[]> => {
  return http.get(`/lifecycle/fieldList`);
};

// 生命周期节点保存
export const saveLifeCycleNode = (
  params: saveLifecycleNodeParams,
): Promise<lifecycleNode> => {
  return http.put(`/lifecycle/node/save`, params);
};
// 生命周期节点删除
export const deleteLifeCycleNode = (
  id: string,
  nodeId: string,
): Promise<null> => {
  return http.delete(`/lifecycle/node/${id}/${nodeId}`);
};
// 生命周期连线保存
export const saveLifeCycleEdge = (
  params: saveLifecycleEdgeParams,
): Promise<lifecycleEdge> => {
  return http.put(`/lifecycle/edge/save`, params);
};
// 生命周期连线删除
export const deleteLifeCycleEdge = (
  id: string,
  edgeId: string,
): Promise<null> => {
  return http.delete(`/lifecycle/edge/${id}/${edgeId}`);
};
